package com.yaowk.sfp.system.server.service.base;

import com.yaowk.sfp.system.server.entity.SysUser;
import com.yaowk.sfp.system.server.entity.SysUser;
import java.lang.Long;
import java.util.Date;
import com.yaowk.sfp.system.server.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import com.yaowk.sfp.common.db.BaseServiceImpl;
import java.lang.String;
import java.lang.Byte;
import com.yaowk.sfp.system.api.model.User;
import com.yaowk.sfp.system.server.service.IUserService;

public abstract class UserServiceBase extends BaseServiceImpl<User, SysUser, Long> implements IUserService {

	@Autowired
	private UserDao dao;

	@Override protected UserDao getDao() {
	return dao;
	}

	@Override
	public User entity2Model(SysUser entity) {
		User model = null;
		if(isNotEmpty(entity)){
			model = new User();
			model.setId(entity.getId());
			model.setUsername(entity.getUsername());
			model.setPassword(entity.getPassword());
			model.setNickName(entity.getNickName());
			model.setHeadUrl(entity.getHeadUrl());
			model.setCreateTime(entity.getCreateTime());
			model.setStatus(entity.getStatus());
		}
		return model;
	}

	@Override
	public SysUser model2Entity(User model) {
		SysUser entity = null;
		if(isNotEmpty(model)){
			entity = new SysUser();
			entity.setId(model.getId());
			entity.setUsername(model.getUsername());
			entity.setPassword(model.getPassword());
			entity.setNickName(model.getNickName());
			entity.setHeadUrl(model.getHeadUrl());
			entity.setCreateTime(model.getCreateTime());
			entity.setStatus(model.getStatus());
		}
		return entity;
	}

	@Override
	public SysUser updateParams(User model) {
		SysUser entity = dao.findOne(model.getId());
		if(isNotEmpty(model.getUsername()))
			entity.setUsername(model.getUsername());
		if(isNotEmpty(model.getPassword()))
			entity.setPassword(model.getPassword());
		if(isNotEmpty(model.getNickName()))
			entity.setNickName(model.getNickName());
		if(isNotEmpty(model.getHeadUrl()))
			entity.setHeadUrl(model.getHeadUrl());
		if(isNotEmpty(model.getCreateTime()))
			entity.setCreateTime(model.getCreateTime());
		if(isNotEmpty(model.getStatus()))
			entity.setStatus(model.getStatus());
		return entity;
	}


}